/*
 *  System.cpp
 *  vorpal
 *
 *  Created by rwebb on 4/05/08.
 *
 */

#include "System.h"
#include "VM.h"
#include "VmGroup.h"

namespace Vorpal{

bool System::Receive(Message msg, uint32_t numArgs, VM *vm){
	switch(msg){
		case msg_hello:
			puts("hello");
			//vm->PrintStack();
			vm->Drop(numArgs - 1);
			return true;
			break;
		case msg_argCount:
			vm->Drop(numArgs);
			vm->PushPtr(vm->NewNumber(args.size()));
			return true;
			break;
		case msg_arg: {
			Handle<Number> indexObj = Translate<Number>(vm->FromTop(0).Ptr());
			uint32_t index = uint32_t( indexObj->Value() );
			Require(index < args.size());
			vm->Drop(numArgs);
			vm->PushPtr(new String(args[index]));			
			return true;
			break;
		}
		default: {
			return Object::Receive(msg, numArgs, vm);
		}
	}
	return false;
}

}
